package com.exm.sql.model.vo;

import lombok.Data;

@Data
public class ResponseResult<T> {

    private int status;  // 状态码
    private String message;  // 响应信息
    private T data;  // 响应数据

    // 默认的成功响应
    public static final int SUCCESS = 200;
    public static final int ERROR = 500;
    public static final int TOKEN_EXPIRATION=401;
    public static final int TOKEN_MISSING=401;

    // 无数据的成功响应
    public static ResponseResult<?> success() {
        return new ResponseResult<>(SUCCESS, "操作成功", null);
    }

    // 带数据的成功响应
    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<>(SUCCESS, "操作成功", data);
    }

    // 带消息和数据的成功响应
    public static <T> ResponseResult<T> success(String message, T data) {
        return new ResponseResult<>(SUCCESS, message, data);
    }

    // 失败响应
    public static ResponseResult<?> error(String message) {
        return new ResponseResult<>(ERROR, message, null);
    }
    // 失败响应
    public static ResponseResult<?> error() {
        return new ResponseResult<>(ERROR, "操作失败", null);
    }

    // 身份认证过期响应
    public static <T> ResponseResult<T> tokenError() {
        return new ResponseResult<>(TOKEN_EXPIRATION, "身份认证过期",null);
    }
    // 身份认证过期响应
    public static <T> ResponseResult<T> tokenMiss() {
        return new ResponseResult<>(TOKEN_MISSING, "无身份认证",null);
    }

    // 带数据的失败响应
    public static <T> ResponseResult<T> error(String message, T data) {
        return new ResponseResult<>(ERROR, message, data);
    }

    // 构造函数
    private ResponseResult(int status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResponseResult{" +
                "status=" + status +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
